/**
 * Created with JetBrains WebStorm.
 * User: zhoums
 * Date: 14-3-3
 * Time: 上午10:11
 * blog function file { issue,edit,delete }
 */

var $contentBox = $(".blog_c");

$(function () {
    var _this = this;
    KindEditor.ready(function (K) {
        window.editor = K.create('#editor_id', {});
    });
    $(".ke-container").css({"display": "inline-block"})
    $("#issue_blog").click(render_issueBox);
    changeAbstract();

    $("#blog_sbm").on("click",issueBlog);



})

    function issueBlog() {
        var title = $("#blogTitle").val(), abstract = $("#abstract").val(), validate = "", isNull = false;
        editor.sync();
        var htmls = editor.html();
        title === "" ? eval('validate+="日志标题 ";isNull=true') : "";
        htmls === "" ? eval('validate+="日志内容 ";isNull=true') : "";
        validate += "不能为空！"
        if (isNull) {
            alert(validate);
//                $(".ke-content").css({"border-color":"#f50"})
            return;
        } else {
            var param = $('#blog_issu').serialize();
            $.ajax({
                url: fm.config.buildPath + "account/backEnd/issueBlog.php",
                type: "post",
                data: param,
                success: function (data) {
                    var oData = eval("(" + data + ")");
                    if (oData.status == "success") {
                        $(this).wBox({show: true, html: '<div style="padding:10px;">博客发布成功！</div>', noTitle: true});
//                            setTimeout($("#wBox").remove(),5000);
                    }
                }
            })
        }
    }

    /*
     * fn render_issueBox:渲染发布表半单
     * */
    function render_issueBox() {
        var $issueForm = $(".warp-issueBlog"), $blogList = $contentBox.find("ul");
        //清空BLOG内容列表
        $(".blog_text").slideUp("fast");
        $blogList.slideUp("fast", function () {
            $issueForm.slideDown("slow")
        });
    }

function changeAbstract(){
    $(".abstract").focus(function(){
        $(this).animate({"height":"60px"},"fast");
    });
    $(".abstract").blur(function(){
        if($(this).val()==""){
            $(this).animate({"height":"30px"},"fast");
        }
    })


}
